# -*- coding: utf-8 -*-
'''对系统模块os目录，文件操作的扩展'''


import os
import sys
import stat
import shutil
import cPickle
import time
import tempfile
import fnmatch

#pywin32 操作系统依赖类库
import win32file
import pywintypes

def setFileModifyTime(path,modifyTime):
    """
    setFileModifyTime(basestring path,long modifyTime)
    """
    f=None
    try:
        f=file(path,'a+')
        hfile=win32file._get_osfhandle(f.fileno( ))
        newTime=pywintypes.Time(modifyTime)
        win32file.SetFileTime(hfile,newTime,newTime,newTime)

    except Exception ,e:
        raise Exception,"setFileModifyTime"+path+"\n inner exception:"+str(e)
    finally:
        if f is not None : f.close()
 
def getHexdigest(filePath):
    """ 
       getHexdigest(str filePath) -> str
    
       return  md5 hash of the file 
    """
    f = open(filePath,'rb')
    import md5
    hsh = md5.new()
    while True:
        data = f.read(2048)
        if not data: break
        hsh.update(data)
    f.close()
    return hsh.hexdigest()

